import { InjectionKey } from '@vue/runtime-core'
import {
  createStore,
  Store,
  StoreOptions,
  useStore as baseUseStore
} from 'vuex'
import createPersistedState from 'vuex-persistedstate'
import { store as user, UserState } from './modules/user'

export interface RootState {}
const state: RootState = {}

export interface TypeState extends RootState {
  user: UserState
}

export const key: InjectionKey<Store<TypeState>> = Symbol('storeKey')
export const store: StoreOptions<RootState> = createStore({
  state,
  modules: {
    user
  },
  plugins: [
    createPersistedState({
      paths: ['user']
    })
  ]
})

export default function useStore () {
  return baseUseStore(key)
}
